#include "FileTest.h"
#include <stdio.h>
#include <string.h>

/*
 * Created: 2/27/12; CGP
a) Create a new file, call it X (opened for writing)
b) Create a new (different) file, call it Y (opened for writing)
c) List the files to make sure they appear in directory
d) Close the files
e) Delete the files
f) List the files to make sure they don't appear in directory
 */

int main(int argc, char *argv[]) {
    int length;
    printf("Starting test...\n"); fflush(stdout);
    FileTest ft;
    const char *fileName1 = "X";
    const char *fileName2 = "Y";
    File *f1, *f2;

    printf("Creating a file...\n");
    f1 = new File(fileName1, "w");
    f2 = new File(fileName2, "w");

    if (ft.dir->LookUp(fileName1) == NULL) {
        printf("ERROR: %s file is not present in directory\n", fileName1);
    }

    if (ft.dir->LookUp(fileName2) == NULL) {
        printf("ERROR: %s file is not present in directory\n", fileName2);
    }

    if (! f1->Close()) {
        printf("ERROR: Could not close file\n");
    }
    delete f1;

    if (! f2->Close()) {
        printf("ERROR: Could not close file\n");
    }
    delete f2;

    if (! File::Delete(fileName1)) {
        printf("ERROR: Could not delete file: %s\n", fileName1);
    } else {
        printf("SUCCESS: It seems we were able to delete the file!\n");
    }

    if (! File::Delete(fileName2)) {
        printf("ERROR: Could not delete file: %s\n", fileName2);
    } else {
        printf("SUCCESS: It seems we were able to delete the file!\n");
    }

    if (ft.dir->LookUp(fileName1) != NULL) {
        printf("ERROR: %s file is present in directory after deletion\n", fileName1);
    }

    if (ft.dir->LookUp(fileName2) != NULL) {
        printf("ERROR: %s file is present in directory after deletion\n", fileName1);
    }
}





